package com.agency8x.model;

import com.agency8x.model.base.BaseBankcardModel;
import com.agency8x.util.RegexUtil;
import com.jfinal.plugin.activerecord.Page;

public class BankcardModel extends BaseBankcardModel<BankcardModel> {

    public static final BankcardModel me = new BankcardModel().dao();

    /**
     * 所有 sql 与业务逻辑写在 Service 中，在此放在 Model 中仅为示例
     */
    public Page<BankcardModel> paginate(int pageNumber, int pageSize, String where) {
        String sql = "select * ";
        String sqlFrom = "from t_bankcard";
        if (where != null && !"".equals(where.trim())) {
            if (RegexUtil.isNumeric(where)) {
                sqlFrom = sqlFrom + "where user_id = " + where;
            }
        }
        return paginate(pageNumber, pageSize, sql, sqlFrom);
    }

    public BankcardModel findByUserId(Integer user_id) {
        String sqlstmt = "select top 1 * from t_bankcard where user_id=?";
        return findFirst(sqlstmt, user_id);
    }
}
